package com.leolian.spring01.aop.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MoocAspect {
	
	@Pointcut("execution(* com.leolian.spring01.aop.aspectj.biz.*Biz.*(..))")
	public void pointcut(){}
	
	@Pointcut("within(com.leolian.spring01.aop.aspectj.biz.*)")
	public void bizPoint(){}
	
	
	@Before("pointcut()")
	public void before(){
		System.out.println("MoocAspect  Before...");
	}
	
	@Before("pointcut() && args(param)")
	public void beforeWithParam(String param){
		System.out.println("MoocAspect  beforeWithParam :"+param);
	}
	
	@Before("pointcut() && @annotation(moocMethod)")
	public void beforeWithAnntation(MoocMethod moocMethod){
		System.out.println("MoocAspect  beforeWithAnntation :"+moocMethod.value());
	}
	
	@AfterReturning(pointcut="bizPoint()",returning="returnValue")
	public void afterThrowing(Object returnValue){
		System.out.println("MoocAspect  AfterReturning :"+returnValue);
	}
	
	@AfterThrowing(pointcut="pointcut()", throwing="exception")
	public void afterThrowing(RuntimeException exception){
		System.out.println("MoocAspect  AfterThrowing :"+exception);
		exception.printStackTrace();
	}
	
	@After("pointcut()")
	public void after(){
		System.out.println("After ...");
	}
	
	@Around("pointcut()")
	public void around(ProceedingJoinPoint pjp) throws Throwable{
		System.out.println("Around 1 ...");
		Object obj = pjp.proceed();
		System.out.println("Around 2 ...");
	}
	
}
